<?php

/**
 * 
 */
class Admin_Form_Local extends Zend_Form
{
	/**
	 * (non-PHPdoc)
	 * @see Zend_Form::init()
	 */
	public function init ()
	{
		//Atributos
		$this->setMethod( Zend_Form::METHOD_POST );
		$this->setEnctype( Zend_Form::ENCTYPE_MULTIPART );
		
		$this->setAttrib( 'class', 'form' );
		$this->setAttrib( 'id', 'form-local' );
		$this->setAttrib( 'target', 'upload_target' );
		$this->setAttrib( 'onSubmit', 'return save(this);' );
		
		//Elementos
		$elements = array();
		
		$decorator = array( 'ViewHelper' );
		
		$elements[] = $this->createElement( 'hidden', 'lcl_id' )
			->setDecorators( $decorator );

		$dbRegiao = App_Model_DbTable_Factory::get( 'Regiao' );
		
		$rows = $dbRegiao->fetchAll();
		
		$opt = array( '' => null );
		
		foreach ( $rows as $row )
			$opt[$row->reg_id] = $row->reg_titulo;
			
		$elements[] = $this->createElement( 'select', 'reg_id' )
			->setDecorators( $decorator )
			->addMultiOptions( $opt )
			->setRequired( true );
			
		$elements[] = $this->createElement( 'text', 'lcl_titulo' )
			->addFilter( 'StripTags' )
			->addFilter( 'StringTrim' ) 
			->setAttrib( 'maxlength', 100 )
			->setAttrib( 'class', 'full-width' )
			->setDecorators( $decorator )
			->setRequired( true );
			
		$elements[] = $this->createElement( 'textarea', 'lcl_descricao' )
			->setAttrib( 'class', 'full-width' )
			->setAttrib( 'rows', 10 )
			->setAttrib( 'cols', 55 )
			->setDecorators( $decorator );
                
		$elements[] = $this->createElement( 'textarea', 'lcl_leiamais' )
			->setAttrib( 'class', 'full-width' )
			->setAttrib( 'rows', 10 )
			->setAttrib( 'cols', 55 )
			->setDecorators( $decorator );
                
		$elements[] = $this->createElement('checkbox', 'lcl_destaque')
			->setAttrib('class', 'mini-switch')
			->setValue(0)
			->setDecorators($decorator);
		
		$elements[] = $this->createElement( 'hidden', 'img_id' )
			->setIsArray( true )
			->setDecorators( $decorator );
			
		$config = ini_get( 'upload_max_filesize' );
		$size 	= (int) $config;
		$unit 	= preg_replace( '/[0-9]/', '', $config );
		
		$elements[] = $this->createElement( 'file', 'imagem' )
			->addValidators(
				array(
					array( 'Count', false, 5 ),
					array( 'Size', false, App_General_ByteSize::convert($size, $unit, 'B') ),
					array( 'Extension', false, 'jpg,png,gif,jpeg')
				)
			)
			->setValueDisabled( true )
			->setDecorators( array('File') )
			->setAttrib( 'onChange', "showFileSelected(this);" )
			->setAttrib( 'class', 'input-file' )
			->setIsArray( true );
	
		$this->addElements( $elements );
	}
}
